#include<bits/stdc++.h>
using namespace std;
#define maxn 101
int head[maxn]={0};
int dfn[maxn]={0};
int low[maxn]={0};
bool ins[maxn]={0};
int cnt = 0,num = 0;
stack<int> s;
struct Node{
    int to,next;
}e[maxn];

void add(int u,int v)
{
    e[++cnt].to = v;
    e[cnt].next = head[u];
    head[u] = cnt;
}

void tarjan(int u)
{
    dfn[u]=low[u]=++num;
    ins[u]=true;
    s.push(u);
    for(int i = head[u];i;i = e[i].next)
    {
        int v = e[i].to;
        if(!dfn[v])
        {
            tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        else if(ins[v])
        {
            low[u]=min(low[u],dfn[v]);
        }
    }
    if(low[u]==dfn[u])
    {
        int v;
        cout<<"强连通分量"<<endl;
        do 
        {
            v=s.top();
            s.pop();
            cout<<v<<" ";
            ins[v]=false;
        }while (v!=u);
        cout<<endl;
    }
}

int main()
{
    int m,n;
    cin>>m>>n;
    for(int i = 0;i < m;i++)
    {
        int x,y;
        cin>>x>>y;
        add(x,y);
    }
    for(int i =1;i<=n;i++)
    {
        if(!dfn[i])
        {
            tarjan(i);
        }
    }
}